# -*-coding:utf-8 -*-

"""
# File       : service.py
# Time       : 2022年5月6日23:54:53
# Author     : puppet洛洛
# Description:
"""

import os

import django
from tornado.options import options, define
from tornado import httpserver
from tornado.ioloop import IOLoop
from tornado import wsgi
from django.core.wsgi import get_wsgi_application
from rentalsite.settings import ROOT_URLCONF, CurrentPort


# Getting django project name from settings.py.
DjangoProjectName = str(ROOT_URLCONF).split('.')[0]
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{}.settings'.format(DjangoProjectName))
# Allowing django to use async method.
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"

application = get_wsgi_application()
define('Currentport', CurrentPort, type=int)
print("CurrentPort--", CurrentPort)


if __name__ == '__main__':
    options.parse_command_line()
    app = wsgi.WSGIContainer(application)
    http_server = httpserver.HTTPServer(app, xheaders=True)
    http_server.listen(options.Currentport)
    IOLoop.instance().start()
    print("------------Successfully Started!------------")


